﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EquipmentInfoForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.EquipmentInfoForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>添加、修改设备</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" method="post">
    <input name="EqID" class="mini-hidden" />
    <div style="padding-left: 11px; padding-bottom: 5px;">
        <table style="table-layout: fixed;">
            <tr>
                <td style="width: 120px;" align="right">
                    所属产线：
                </td>
                <td style="width: 300px;">
                    <div id="LineID" name="LineID" class="mini-combobox" style="width: 300px;" popupwidth="300"
                        required="true" textfield="LineName" valuefield="LineID" url="../Service/BasicDataManageHandler.ashx?action=GetLineListByCombobox">
                        <div property="columns">
                            <div header="产线编号" field="LineCode">
                            </div>
                            <div header="产线名称" field="LineName">
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="width: 120px;" align="right">
                    设备编号：
                </td>
                <td style="width: 300px;">
                    <input name="EqCode" emptytext="请输入设备编号" style="width: 300px;" class="mini-textbox"
                        onvaluechanged="onEqCodeChanged" required="true" />
                </td>
            </tr>
            <tr>
                <td style="width: 120px;" align="right">
                    设备名称：
                </td>
                <td style="width: 300px;">
                    <input name="EqName" emptytext="请输入设备名称" style="width: 300px;" class="mini-textbox"
                        required="true" />
                </td>
            </tr>
            <tr>
                <td style="width: 120px;" align="right">
                    描述：
                </td>
                <td style="width: 300px;">
                    <input name="EqDesc" class="mini-textarea" style="width: 300px; height: 100px;" />
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" iconcls="icon-save" onclick="onOk" style="width: 60px; margin-right: 20px;">
            保存</a> <a class="mini-button" iconcls="icon-cancel" onclick="onCancel" style="width: 60px;">
                取消</a>
    </div>
    <script type="text/javascript">
        mini.parse();
        var form = new mini.Form("form1");
        var action;
        function onOk(e) {
            SaveData();
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

        function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                action = data.action;
                $.ajax({
                    url: "../service/BasicDataManageHandler.ashx?action=GetEquipmentInfo&EqID=" + data.EqID,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                    }
                });
            }
        }
        function onEqCodeChanged() {
            var lineID = mini.getbyName("LineID").getValue();
            var EqCode = mini.getbyName("EqCode").getValue();
            if (lineID) {
                if (EqCode) {
                    $.ajax({
                        url: "../service/PublicHandler.ashx?action=CheckedCodes&tableName=UT_Equipment&fieldName1=LineID&fieldName2=EqCode&Code1=" + lineID + "&Code2=" + EqCode,
                        success: function (text) {
                            if (text > 0) {
                                mini.alert(EqCode + "已经存在！请重新输入！");
                                mini.getbyName("EqCode").setValue("");
                            }
                        },
                        error: function () {
                        }
                    });
                }
            }
            else {
                mini.alert("请先选择车间！");
            }
        }
        function SaveData() {
            var o = form.getData();
            var json = mini.encode([o]);
            form.validate();
            if (form.isValid() == false) return;
            if (action == "edit") {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=ModifyEquipment",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            else {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=AddEquipment",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }
        function GetData() {
            var o = form.getData();
            return o;
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
    </form>
</body>
</html>
